<template>
    <div class="nav-top" :class="{ 'is-index': isIndex }">
        <div class="logo" @click="toIndex"></div>
        <div class="nav-buttons">
            <div class="login-btn" v-show="!isScoreQueryPage" @click="toScoreQuery">学生端</div>
            <div v-show="!isLoggedIn" class="login-btn" @click="toAdminLogin">管理员登录</div>
            <div v-show="isLoggedIn && !isAdminPage" class="login-btn" @click="toAdmin">管理端</div>
            <div v-show="isLoggedIn" class="login-btn" @click="outLogin">退出登录</div>
        </div>
    </div>
</template>

<script setup>
import {computed} from 'vue'
import {useRouter} from 'vue-router'
import useAppStore from '@/store/modules/app.js'


const appStore = useAppStore();

const isLoggedIn = computed(() => appStore.token === 'login-success!')
const router = useRouter()

// 这里需要监听当前路由信息的变化, 判断是不是  login 页面


const isAdminPage = computed(() => router.currentRoute.value.path.startsWith('/tabs'))
const isScoreQueryPage = computed(() => router.currentRoute.value.path.startsWith('/scoreQuery'))

const toIndex = () => {
    router.push('/index')
}
const toScoreQuery = () => {
    router.push('/scoreQuery')
}
const toAdminLogin = () => {
    router.push('/login')
}
const toAdmin = () => {
    router.push('/tabs')
}

const outLogin = () => {
    appStore.setToken(null)
    router.push('/');
}
const isIndex = computed(() => router.currentRoute.value.path === '/index')
</script>

<style lang="scss" scoped>
.nav-top {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 650px;
    height: 50px;
    padding: 15px 25px;
    background: linear-gradient(#ff5a00 0%, #f76d24 100%);
    backdrop-filter: blur(15px);
    transition: all 0.3s ease;
    overflow: visible;

    &::before,
    &::after {
        content: '';
        position: absolute;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba($primary-color, 0.1);
        animation: float 6s infinite ease-in-out;
    }

    &::before {
        top: -20px;
        left: 10%;
        animation-delay: -2s;
    }

    &::after {
        bottom: -15px;
        right: 15%;
        width: 30px;
        height: 30px;
        animation-delay: -4s;
    }

    .nav-bg {
        display: none;
    }

    .logo {
        width: 300px;
        height: 42px;
        margin-top: 2px;
        margin-left: 10px;
        cursor: pointer;
        background-image: url(@/assets/logo.png);
        background-repeat: no-repeat;
        background-size: contain;

        &:hover {
            transform: translateX(-7px);
            transition: all 0.3s;
        }
    }

    .nav-buttons {
        display: flex;
        gap: 14px;
        margin-right: 10px;

        .login-btn {
            width: 88px;
            height: 24px;
            line-height: 24px;
            padding: 8px 10px;
            color: $primary-color;
            border: 3px solid white;
            border-radius: 10px;
            color: white;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s;
            background-color: #df5a21;

            &:hover {
                background-color: #3f3d3c;
                transform: translateY(-2px);
                color: white;
            }
        }
    }
}

.is-index {
    position: relative;
    min-width: 1400px;
    backdrop-filter: none;
    background: transparent;
    z-index: 999;

    .logo {
        overflow: visible;
        transform: scale(1.4) translateY(20px);
        transition: none;
        margin-left: 60px;

        &:hover {
            transform: scale(1.4) translateY(20px);
            transition: none;
        }
    }
}
</style>
